<%@ page import="java.util.*, milu.*, milu.models.*,com.google.appengine.api.datastore.*" %>

<jsp:include page="/header.jsp" />
<link rel="stylesheet" href="/stylesheets/MooEditable.css"> 
<script src="/js/mootools-yui-compressed.js"></script> 
<script src="/js/MooEditable.js"></script> 
<script> 
window.addEvent('domready', function(){
    $('content').mooEditable();
});
</script> 
<style>
.mooeditable-container {
    float: right;
    width: 486px !important;
    height: 200px;
}

</style>
<%
Recipe recipe = (Recipe)request.getAttribute("recipe");
%>
        <div id="link-form">
			
						
            <%
            String error = (String)request.getAttribute("error");
            if(error != null) {
            %>
			<h2 class="cabin error"><%=error%></h2>
            <% } else { %>
			<h2 class="cabin">Inserisci Ricetta:</h2>
            <% } %>
			
			
            <% 
            String recipeId = (String)request.getAttribute("recipeId");
            if(recipeId != null) { // we're editing it if %>
            <form action="/edit-recipe/<%=recipeId%>" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="recipeId" value="<%=recipeId%>" />
            <% } else { %>
            <form action="/add" method="post" enctype="multipart/form-data">
            <% } %>
				<p>
					<label for="image">Immagine:</label>
                    <input id="image" type="file" name="image">
                    <%
                    if(recipe != null && recipe.getThumbKey() != null) {
                    %>
                    <img src="/serve/<%=recipe.getThumbKey().getId()%>.png" />
                    <% } %>
				</p>
				<p>
					<label for="title">Titolo:</label>
                    <input id="title" type="text" name="title" value="<%=(recipe!=null ? recipe.getTitle():"")%>" />
				</p>
				<p>
					<label for="content">Contenuto: </label>
                    <textarea id="content" name="content"><%=(recipe!=null ? recipe.getContent().getValue():"")%></textarea>
				</p>
				<p>
					<label for="ingredients">Ingredienti: </label>
                    <textarea id="ingredients" name="ingredients"><%=(recipe!=null ? recipe.getIngredients().getValue():"")%></textarea>
				</p>
				<p>
					<label for="tags">Tag: </label>
                    <%
                    String tagsString = "";
                    if(recipe != null) {
                        for(String tag : recipe.getTags()) {
                            tagsString += tag + " ";
                        }
                    }
                    %>
                    <input id="tags" type="text" name="tags" value="<%=(recipe!=null ? tagsString:"")%>"/>
				</p>
				
				<p class="last-p"><button type="submit">Crea!</button></p>
			</form>
        </div><!-- /link-form -->

<jsp:include page="/footer.jsp" />
